package com.itheima.d6_synchronized_lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket implements Runnable {
    private int  ticker = 100;
    Lock lk = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            try {
                lk.lock();
                if (ticker <=0){
                    break;
                }else {
                    ticker --;
                    System.out.println(Thread.currentThread().getName()+ "窗口剩余票数"+ticker);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }finally{
                lk.unlock();
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
